next up previous contents index
Next: Methods Up: Classes Previous: Class definitions

Class instantiation

Classes must be created using their constructor. Remember that a class is a pointer to an object, so when you declare a variable of some class, the compiler just allocates a pointer, not the entire object. The constructor of a class returns a pointer to an initialized instance of the object.

So, to initialize an instance of some class, you would do the following :
listing2313
You cannot use the extended syntax of new and dispose to instantiate and destroy class instances. That construct is reserved for use with objects only.

Calling the constructor will provoke a call to getmem, to allocate enough space to hold the class instance data. After that, the constuctor's code is executed. The constructor has a pointer to it's data, in self.

Remark :


next up previous contents index
Next: Methods Up: Classes Previous: Class definitions

Michael Van Canneyt
Fri Sep 25 09:15:40 MEST 1998